package com.a51work6.qq.server;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;

public class DBHelper {
	// url for database connection
	static String url;
	// create Properties Object
	static Properties info = new Properties();
	
	// run jdbc drivers
	static {
		InputStream input = DBHelper.class.getClassLoader()
				.getResourceAsStream("src/com/a51work6/qq/server/config.properties");
		try {
			// load properties 
			info.load(input);
			// get url from properties
			url = info.getProperty("url");
			// get driver from properties
			String driverClassName = info.getProperty("driver");
			System.out.println(driverClassName);
			Class.forName(driverClassName);
			System.out.println("driver loads success...");
		}catch(ClassNotFoundException e) {
			System.out.println("driver loads failed(class not found)");
		}catch(IOException e) {
			System.out.println("load properties failed");
		}
	}
	public static Connection getConnection() throws SQLException{
		// create database connection
		Connection conn = DriverManager.getConnection(url, info);
		return conn;
	}
	
}
